import axios from '../../extend/axios'
import { ActionContext, ActionTree, GetterTree, MutationTree } from 'vuex'

class State {
  public policy: object = {
    host: '',
    OSSAccessKeyId: '',
    policy: '',
    saveName: '',
    signature: ''
  }
  public num: number = 0
}

const mutations = {
  setPolicy (state: State, res: AjaxResponse) {
    state.policy = res
  },
  changeNum (state: State, val: number) {
    state.num = val
  }
} as MutationTree<State>
const actions = {
  async getPolicy (store: ActionContext<State, any>) {
    try {
      let res = await axios.get('https://1894469675823662.cn-shanghai.fc.aliyuncs.com/2016-08-15/proxy/oss/policy/')
      store.commit('setPolicy', res.data)
    } catch (e) {
      console.log(e)
    }
  }
} as ActionTree<State, any>
const getters = {
  policy (state: State) {
    return state.policy
  },
  num (state: State) {
    return state.num
  }
} as GetterTree<State, any>
const global = {
  namespace: true,
  state: new State(),
  mutations,
  actions,
  getters
}
export default global
